home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / windows / pmcstex.zip / PM4EPM.E < prev    next >
Text File  |  1996-05-17  |  17KB  |  484 lines

  1. /* 
  2.   pm4epm.e
  3.  
  4.   PM for EPM. pm_command family: command with expansion dependend 
  5.   on the currently edited file
  6.  
  7.   c Petr Mikulík - Brno - Czech Republic - 20.2.1996
  8.   mikulik@physics.muni.cz, http://www.sci.muni.cz/~mikulik/
  9.  
  10.   Update for emtex options: 17.5.1996
  11.   Update for dvips options: 15.5.1996
  12.  */
  13.  
  14.  
  15. /* 
  16. USAGE: I use this macro file for actions on the EPM toolbar, and in the package 
  17. CSTeX that implements menu for many (La)TeX related commands.
  18.  
  19. INSTALLATION: 
  20.   1. cite this file (pm4epm) in the  actions.lst  file
  21.   2. write  include pm4epm  into your Profile.erx
  22.   3. You should have already installed EPMTeX and WETEX by Wagner
  23.  
  24. COMMANDS DEFINED HERE:
  25.  pm_expand           - expands the string and then executes it
  26.  pm_command_os2   - expands the string and runs it as os2 program
  27.  pm_command_os2fs - expands the string and runs full-screen os2 program
  28.  pm_command_cmd   - expands the string and runs it through cmd
  29.  pm_command_pm    - expands the string and runs it (only START)
  30.  pm_command_dos    - expands the string and runs it as dos program
  31.  pm_command_dosfs  - expands the string and runs full-screen dos program
  32.  etc. 
  33.  
  34. The expansion depends on the edited file (currently active file in the editor). 
  35.  
  36. SYNTAX of pm_expand WITH EXAMPLE: work file is e:\tmp\a.tex => 
  37.  
  38. Syntax   Internal Variable      Explanation                  Example
  39. %w      EFname               work file name               a
  40. %.w     EFext                  work file extension          tex
  41. %W      EFwholename         full name without extension e:\tmp\a
  42. %.W     EF                     full name                     e:\tmp\a.tex
  43.  
  44.  
  45. The same holds for the Master file specified by the MASTER: key (see below):
  46. %m     %.m   %M   %.M
  47.  
  48. Both types written in the Unix format (i.e. backslahes replaced by slashes): 
  49. %x %.x %X %.X  for the work file      e.g.  %.X = e:/tmp/a.tex
  50. %n %.n %N %.N  for the master file
  51.  
  52. %h MFdrive         drive of the master file (e:)
  53. %d MainDirectory   directory of the master file (\tmp)
  54. %D XMainDirectory directory in the Unix format (/home/petr/tex)
  55.  
  56. Key specifications: 
  57. The work file can have some of the following keyword written on its first line. 
  58. They are expanded as well according to this rules:
  59.  
  60. Syntax     Internal Variable   Introducing key word   If key not specified
  61. %master   MF                 Master:                 MF := EF
  62. %format   TheFormat         Format:                 envir. var. TEXFORMATDEFAULT 
  63.                                                          of "latex"                                                
  64. %etc      TheEtc              Etc:                    empty string
  65. %orient   TheOrient           Orientation:            empty string
  66. %choice   TheChoice          Choice:                 empty string
  67.  
  68. The following are expanded as verbatims, e.i. from the first char occuring after 
  69. the key to the next same char:
  70. %opts                         Opts:                   empty string
  71. %viewopts                     ViewOpts:               empty string
  72. %optsdvips                    dvips:                  empty string
  73. %optsemtex                    EmtexOpt:              empty string
  74.  
  75. The syntax $(Name) expands environmental variable Name
  76.  
  77.  
  78. *** Example 1 ***
  79. We edit file E:\TEXT\FERDA.TEX having the first line
  80. % Master: SEKORA.TEX  Format: latex209  Choice: none
  81.  
  82. Then commands are expanded:
  83. "copy %.W %W.old"     => "copy E:\TEXT\FERDA.TEX E:\TEXT\FERDA.old"
  84. "type %w%.w"          => "type FERDA.TEX"
  85. "%format.cmd %.N"     => "latex209.cmd E:/TEXT/SEKORA.TEX"
  86. "echo %choice *%etc*" => "echo none **"
  87.  
  88. *** Example 2 ***
  89. We edit file E:\TEXT\BROUK.TEX having the first line
  90. % ViewOpts: +/tr1 /m1440+ Etc: does not exist Opts: =any other=
  91. "start cmd /c cykl %.W %format.cmd %N" =>
  92.    "start cmd /c cykl E:\TEXT\BROUK.TEX latex.cmd E:/TEXT/BROUK"
  93. "start /fs dviscr %viewopts %M.dvi" =>
  94.   "start /fs dviscr /tr1 /m1440 e:\text\brouk.dvi"
  95.  
  96. */
  97.  
  98. include 'stdconst.e'
  99.  
  100.  
  101. /************************ CONSTANTS *********************************/
  102.  
  103. const
  104.  
  105.  PM_STARTos2   = 'start /C /WIN '
  106.  PM_STARTos2fs = 'start /C /FS '
  107.  PM_STARTcmd  = 'start /C /WIN cmd /c '
  108.  PM_STARTpm   = 'start '
  109.  PM_STARTdos   = 'start /C /WIN /DOS command.com /c '
  110.  PM_STARTdosfs = 'start /C /FS /DOS command.com /c '
  111.  
  112. /* Message strings */
  113.  
  114.  pm_expand_inf = "Expand command with: Work file: %w (name) %.w (ext) %W (path\name) %.W (full name); Main drive:\dir %d; 'MASTER:' file: %m %.m %M %.M; 'FORMAT:' %format 'ORIENTATION:' %orient; 'ETC:' %etc; 'CHOICE:' %choice; Verbatims: 'EMTEXOPT:' %optsemtex; 'DVIPS:' %optsdvips; 'VIEWOPTS:' %viewopts; 'OPTS:' %opts"
  115.  pm_command_os2_inf = "Expand command line (as pm_expand) and execute OS/2 exe program"
  116.  pm_command_os2fs_inf = "Expand command line (as pm_expand) and execute full-screen OS/2 exe program"
  117.  pm_command_cmd_inf = "Expand command line (as pm_expand) and execute .cmd file"
  118.  pm_command_pm_inf = "Expand command line (as pm_expand) and execute Prezentation Manager program"
  119.  pm_command_dos_inf = "Expand command line (as pm_expand) and execute dos exe program"
  120.  pm_command_dosfs_inf = "Expand command line (as pm_expand) and execute dos exe program (full screen)"
  121.  
  122.  
  123. /* The following command adds the action commands to the list */
  124.  
  125. DEFINIT
  126.   universal pm4epm_MasterNotFound
  127.  
  128. DEFC pm4epm_actionlist
  129. universal ActionsList_FileID
  130.  
  131.  insertline 'pm_expand'pm_expand_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
  132.  insertline 'pm_command_cmd'pm_command_cmd_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
  133.  insertline 'pm_command_os2'pm_command_os2_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
  134.  insertline 'pm_command_os2fs'pm_command_os2fs_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
  135.  insertline 'pm_command_pm'pm_command_pm_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
  136.  insertline 'pm_command_dos'pm_command_dos_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
  137.  insertline 'pm_command_dosfs'pm_command_dosfs_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
  138.  
  139.  
  140.  
  141. /*************************** ROUTINES ******************************/
  142.  
  143. DEFPROC PM_GetNextWord ( WhichWord, line, uline )
  144. -- routine returns the next word after the keyword  WhichWord  or  WhichWord:
  145. i = wordpos(WhichWord,uline)
  146. if i=0 then i = wordpos(WhichWord':',uline) endif
  147. if i=words(uline) then i=0; TheWord='' endif
  148. if i<>0 then TheWord=word(line,i+1)
  149.          else TheWord='' 
  150.          endif
  151. return TheWord
  152.  
  153.  
  154. DEFPROC PM_GetNextWordOptions ( WhichWord, line, uline )
  155. -- routine scans for WhichWord. The first char of the next word as taken as the 
  156. -- key char. Then line is copied to TheOpts until the next key char appears. 
  157. -- This is similar to \verb*TheOpts...* in LaTeX
  158. i = wordpos(WhichWord,uline)
  159. if i=0 then i = wordpos(WhichWord':',uline) endif
  160. if i=words(uline) then i=0; TheOpts='' endif
  161. if i<>0 
  162.   then TheOpts=subword(line,i+1,words(line)-i)
  163.     KeyChar=substr(TheOpts,1,1); TheOpts=delstr(TheOpts,1,1)
  164.     i=pos(KeyChar,TheOpts)
  165.     if (i<>0) then TheOpts=substr(TheOpts,1,i-1) endif
  166.   else TheOpts=''
  167.   endif
  168. return TheOpts
  169.  
  170.  
  171. DEFPROC PM_SubstKeys ( TheCommand, TheKey, ByWhat )
  172. -- routine substitutes TheKey strings by ByWhat strings in TheCommand
  173. i = pos(TheKey,TheCommand)
  174. do while (i<>0)
  175.    l = length(TheKey)
  176.    TheCommand = substr(TheCommand,1,i-1)ByWhat''substr(TheCommand,i+l,length(TheCommand)-i-l+1)
  177.    i = pos(TheKey,TheCommand)
  178.    end
  179. return TheCommand
  180.  
  181.  
  182. DEFPROC PM_SubstEnvironment ( TheCommand )
  183. -- routine substitutes the environmental variables (like $(PATH)) within TheCommand
  184. i = pos('$(',TheCommand)
  185. do while (i<>0)
  186.    e = substr(TheCommand,i+2,length(TheCommand)-i-2)
  187.    TheCommand = substr(TheCommand,1,i-1)
  188.    i = pos(')',e)
  189.    if i>0 
  190.      then TheCommand=TheCommand''get_env(substr(e,1,i-1))''substr(e,i+1,length(e)-i-1)
  191.      else TheCommand=TheCommand''get_env(substr(e,1,length(e)))
  192.    endif
  193.    i = pos('$(',TheCommand)
  194.    end
  195. return TheCommand
  196.  
  197.  
  198. DEFPROC save_the_ring() =
  199. n = filesinring()
  200. for i = 1 to n
  201.   if .modif